var h = $(window).height(),
    type = 0,
    nowIndexs = 0,
    imgNum = $('#allImg img').length,
    imgW = $('.infoR').width(),
    key = '';
$(function(){
    $('.row-hoof').css({height: h, backgroundColor: '#d5dbe7'});
    $('.newStyle').css({height: h - 20 + 'px'});
    $('.content').css('height',h - 160 + 'px');
    $(window).resize(function(){
        h = $(window).height();
        $('.row-hoof').css({height: h, backgroundColor: '#d5dbe7'});
        $('.newStyle').css({height: h - 20 + 'px'});
    });
    getInfo();
})

function nofind(item){
    item.src = 'common/img/nothing.png';
    item.onerror = null;
}
function seeAll(item){
    if($(item).find('i').hasClass('fa-angle-down')){
        $(item).html('<i class="fa fa-angle-up"></i>收起')
        $(item).siblings('.introF').animate({
            maxHeight: $(item).siblings('.introF').children('.intro').height()
        },200)
    } else{
        $(item).html('<i class="fa fa-angle-down"></i>展开');
        $(item).siblings('.introF').animate({
            maxHeight: '80px'
        },200)
    }
}
function showDetail(uniq){
    layer.open({
        type: 2,
        area: ['90%', h * 0.9 + 'px'],
        fixed: false, //不固定
        maxmin: false,
        content: 'layer/layer.html?' + uniq + '&' + $('#userId').val()
    });
}
function nulls(item){
    var callback;
    if(item != null && item != undefined){
        callback = item;
    } else {
        callback = '无';
    }
    return callback;
}
function searchKeyCode(event){
    event = event ? event : window.event;
    if(event.keyCode == '13'){
        getInfo();
    }
}
function attention(item){
    var index = $(item).parent().index();
    layer.open({
        type: 1,
        title: '确认删除？', //不显示标题栏
        closeBtn: false,
        area: '300px;',
        shade: 0.8,
        id: 'LAY_layuipro', //设定一个id，防止重复弹出
        resize: false,
        btn: ['删除', '取消'],
        btnAlign: 'c',
        moveType: 1, //拖拽模式，0或者1
        content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">确认删除！</div>',
        success: function(layero){
            var btn = layero.find('.layui-layer-btn');
            btn.find('.layui-layer-btn0').click(function(){
                $.ajax({
                    type: 'post',
                    url: baseUrls + 'attention/del',
                    data: {ajbh: $(item).parent().find('input').val(),yhm: $('#userId').val()},
                    before: function(){
                        Loading();
                    },
                    success: function(response){
                        closeLoading();
                        if(response.responseCode == '1000'){
                            Msg('删除成功');
                            $(item).parent().remove();
                        }else{
                            Msg('删除失败');
                        }
                    },
                    error: function(){
                        closeLoading();
                        Msg('删除失败');
                    }
                })
            });
        }
    });

}

function getInfo(){
    var num = Math.floor($('.content').height() / 110);
    $.ajax({
        type: 'get',
        url: baseUrls + 'attention/myCase',
        data: {yhm: $('#userId').val(),pageSize: num,searchInfo: $('.input-hoof').val(),pageIndex: 1},
        beforeSend: function(){
            Loading();
        },
        success: function(response) {
            closeLoading();
            if(response.responseCode == '1000'){
                $('.list').html('');
                if(response.content.list != null){
                    $('#demo_pag1').css('display', 'block');
                    for(var i = 0; i < response.content.list.length; i++){
                        var timeSection = nulls(response.content.list[i].afkssj) + '&nbsp&nbsp~&nbsp&nbsp' + nulls(response.content.list[i].afjssj);
                        if(nulls(response.content.list[i].afkssj) == '无' &&  nulls(response.content.list[i].afjssj) == '无'){
                            timeSection = '无';
                        }
                        if (response.content.list[i].wllj != null && response.content.list[i].wllj != '') {
                            $('.list').append('<li><a href="#" class="title detailTitle" onclick="showDetail(\'' + nulls(response.content.list[i].ajbh) + '\')">' + nulls(response.content.list[i].ajmc) + '</a><h6 class="sTitle">案件编号:&nbsp&nbsp' + nulls(response.content.list[i].ajbh) + ';&nbsp&nbsp时间:&nbsp&nbsp' + timeSection + '</h6><div class="intros"><div class="left"><img src="' + response.content.list[i].wllj + '" onerror="nofind(this)"></div><div class="right"><div class="introF"><p class="intro"><span class="dataKind">简要案情：</span>&nbsp&nbsp' + nulls(response.content.list[i].jyaq) + '</p><p class="intro"><span class="dataKind">现勘信息：</span>&nbsp&nbsp' + nulls(response.content.list[i].ajfxgc) + '</p></div></div></div><span class="delSpan fa fa-trash-o" aria-hidden="true" onclick="attention(this)"></span><input type="hidden" class="ajbh" value="'+ response.content.list[i].ajbh +'"></li>');
                        } else {
                            $('.list').append('<li><a href="#" class="title caseTitle" onclick="showDetail(\'' + response.content.list[i].ajbh + '\')">' + nulls(response.content.list[i].ajmc) + '</a><h6 class="sTitle">案件编号:&nbsp&nbsp' + nulls(response.content.list[i].ajbh) + ';&nbsp&nbsp时间:&nbsp&nbsp' + timeSection + '</h6><div class="introF"><p class="intro"><span class="dataKind">简要案情：</span>&nbsp&nbsp' + nulls(response.content.list[i].jyaq) + '</p><p class="intro"><span class="dataKind">现勘信息：</span>&nbsp&nbsp' + nulls(response.content.list[i].ajfxgc) + '</p></div><span class="delSpan fa fa-trash-o" aria-hidden="true" onclick="attention(this)"></span><input type="hidden" class="ajbh" value="'+ response.content.list[i].ajbh +'"></li>');
                        }
                    }
                    $('#demo_pag1').bs_pagination({
                        totalPages: response.content.pages,
                        visiblePageLinks: 10,
                        currentPage: response.content.pageNum,
                        showGoToPage: false,
                        showRowsPerPage: false,
                        showRowsInfo: false,
                        showRowsDefaultInfo: false,
                        navListContainerClass: 'col-xs-12',
                        onChangePage: function (event, data) {
                            $.ajax({
                                type: 'get',
                                url: baseUrls + 'attention/myCase',
                                data: {
                                    yhm: $('#userId').val(),
                                    pageSize: num,
                                    searchInfo: $('.input-hoof').val(),
                                    pageIndex: data.currentPage
                                },
                                beforeSend: function () {
                                    Loading();
                                },
                                success: function (response) {
                                    closeLoading();
                                    if (response.responseCode == '1000') {
                                        $('.list').html('');
                                        if (response.content.list != null) {
                                            $('#demo_pag1').css('display', 'block');
                                            for(var i = 0; i < response.content.list.length; i++){
                                                var timeSection = nulls(response.content.list[i].afkssj) + '&nbsp&nbsp~&nbsp&nbsp' + nulls(response.content.list[i].afjssj);
                                                if(nulls(response.content.list[i].afkssj) == '无' &&  nulls(response.content.list[i].afjssj) == '无'){
                                                    timeSection = '无';
                                                }
                                                if (response.content.list[i].wllj != null && response.content.list[i].wllj != '') {
                                                    $('.list').append('<li><a href="#" class="title detailTitle" onclick="showDetail(\'' + nulls(response.content.list[i].ajbh) + '\')">' + nulls(response.content.list[i].ajmc) + '</a><h6 class="sTitle">案件编号:&nbsp&nbsp' + nulls(response.content.list[i].ajbh) + ';&nbsp&nbsp时间:&nbsp&nbsp' + timeSection + '</h6><div class="intros"><div class="left"><img src="' + response.content.list[i].wllj + '" onerror="nofind(this)"></div><div class="right"><div class="introF"><p class="intro"><span class="dataKind">简要案情：</span>&nbsp&nbsp' + nulls(response.content.list[i].jyaq) + '</p><p class="intro"><span class="dataKind">现勘信息：</span>&nbsp&nbsp' + nulls(response.content.list[i].ajfxgc) + '</p></div></div></div><span class="delSpan fa fa-trash-o" aria-hidden="true" onclick="attention(this)"></span><input type="hidden" class="ajbh" value="'+ response.content.list[i].ajbh +'"></li>');
                                                } else {
                                                    $('.list').append('<li><a href="#" class="title caseTitle" onclick="showDetail(\'' + response.content.list[i].ajbh + '\')">' + nulls(response.content.list[i].ajmc) + '</a><h6 class="sTitle">案件编号:&nbsp&nbsp' + nulls(response.content.list[i].ajbh) + ';&nbsp&nbsp时间:&nbsp&nbsp' + timeSection + '</h6><div class="introF"><p class="intro"><span class="dataKind">简要案情：</span>&nbsp&nbsp' + nulls(response.content.list[i].jyaq) + '</p><p class="intro"><span class="dataKind">现勘信息：</span>&nbsp&nbsp' + nulls(response.content.list[i].ajfxgc) + '</p></div><span class="delSpan fa fa-trash-o" aria-hidden="true" onclick="attention(this)"></span><input type="hidden" class="ajbh" value="'+ response.content.list[i].ajbh +'"></li>');
                                                }
                                            }
                                        }else{
                                            $('#demo_pag1').css('display', 'none');
                                            Msg();
                                        }
                                    }else{
                                        Msg();
                                    }
                                },
                                error: function(){
                                    closeLoading();
                                    Msg();
                                }
                            })
                        }
                    })
                }else{
                    $('#demo_pag1').css('display', 'none');
                    Msg('暂无数据');
                }
            }else{
                Msg();
            }
        },
        error: function(){
            closeLoading();
            Msg();
        }
    })
}